# Contributor/Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=mypy
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.902
pkgrel=2
pkgdesc="Optional static typing for Python 2 and 3 (PEP484) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://www.mypy-lang.org/"
license=('MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python-mypy_extensions"
  "${MINGW_PACKAGE_PREFIX}-python-psutil"
  "${MINGW_PACKAGE_PREFIX}-python-typed_ast"
  "${MINGW_PACKAGE_PREFIX}-python-typing_extensions"
  "${MINGW_PACKAGE_PREFIX}-python-toml"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.org/packages/source/m/${_realname}/${_realname}-$pkgver.tar.gz")
sha256sums=('9236c21194fde5df1b4d8ebc2ef2c1f2a5dc7f18bcbea54274937cae2e20a01c')

export PYTHONHASHSEED=0

prepare() {
  cd "${srcdir}"

  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done

  local _PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/mypyc"
}
